package com.sanji.sjmallmodule.account;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanji.sjmallapp.BaseActivity;
import com.sanji.sjmallapp.R;
import com.sanji.sjmallmodule.account.ChangePayPwNextActivity;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;

/***
 * 忘记支付密码
 */
public class ForgetPwActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.common_back_img)
    ImageView commonBackImg;
    @BindView(R.id.common_left_tv)
    TextView commonLeftTv;
    @BindView(R.id.forget_pw_send_code)
    TextView forgetPwSendCode;
    @BindView(R.id.forget_pw_get_code)
    EditText forgetPwGetCode;
    @BindView(R.id.forget_pw_bing_phone_number)
    TextView forgetPwBingPhoneNumber;
    @BindView(R.id.chang_pay_pw_next)
    Button changPayPwNext;
    private int time = 0;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {

            }
            super.handleMessage(msg);
        }
    };
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if (time > 0) {
                forgetPwSendCode.setText(getString(R.string.repeate_get) + "(" + time + ")");
                forgetPwSendCode.setTextColor(getResources().getColor(R.color.colorRed));
                forgetPwSendCode.setEnabled(false);
                mHandler.postDelayed(this, 1000);
            } else {
                forgetPwSendCode.setEnabled(true);
                forgetPwSendCode.setText(getString(R.string.get_code));
                forgetPwSendCode.setTextColor(getResources().getColor(R.color.colorDarkGrey));
            }
            time--;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_pw);
        ButterKnife.bind(this);
        initView();
    }

    public void initView() {
        commonLeftTv.setText(getString(R.string.set_forget_pw));
        commonBackImg.setOnClickListener(this);
        forgetPwSendCode.setOnClickListener(this);
        changPayPwNext.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_back_img:
                finish();
                break;
            case R.id.forget_pw_send_code:
                sendCheckCode();
                //测试倒计时
                time = 20;
                mHandler.postDelayed(runnable, 1000);
                forgetPwSendCode.setEnabled(false);
                break;
            case R.id.chang_pay_pw_next:
                //下一步
                intent = new Intent(this, ChangePayPwNextActivity.class);
                startActivity(intent);
                break;
        }
    }

    /**
     * 发送验证码
     */
    public void sendCheckCode() {
        JSONObject json = new JSONObject();
        try {
            json.put("", "");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        String url = "";
    }
}
